import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../pages/home_page.dart';
import '../pages/book_list_page.dart';
import '../pages/love_page.dart';

class BottomNavBarWidget extends StatefulWidget {
  BottomNavBarWidget({Key key}) : super(key: key);
  @override
  _BottomNavBarWidgetState createState() => _BottomNavBarWidgetState();
}

class _BottomNavBarWidgetState extends State<BottomNavBarWidget>
    with SingleTickerProviderStateMixin {
  TabController tabController;
  List _pages = [HomePage(), BookListPage(), LovePage()];
  int currentIndex = 0;

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this)
      ..addListener(() {
        setState(() {
          currentIndex = tabController.index;
        });
      });
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    return Scaffold(
      bottomNavigationBar: CurvedNavigationBar(
        index: currentIndex,
        items: <Widget>[
          Image.asset(
            'images/bottom_nav/home@light.png',
            width: ScreenUtil.getInstance().setWidth(100),
            height: ScreenUtil.getInstance().setHeight(100),
          ),
          Image.asset(
            'images/bottom_nav/book_list@light.png',
            width: ScreenUtil.getInstance().setWidth(100),
            height: ScreenUtil.getInstance().setHeight(100),
          ),
          Image.asset(
            'images/bottom_nav/love@light.png',
            width: ScreenUtil.getInstance().setWidth(100),
            height: ScreenUtil.getInstance().setHeight(100),
          ),
        ],
        onTap: (index) {
          setState(() {
            currentIndex = index;
          });
          tabController.animateTo(index,
              duration: Duration(milliseconds: 300), curve: Curves.ease);
        },
      ),
      body: TabBarView(
        controller: tabController,
        children: <Widget>[
          Container(
            child: _pages[0],
          ),
          Container(
            child: _pages[1],
          ),
          Container(
            child: _pages[2],
          )
        ],
      ),
    );
  }
}
